//
//  Device.m
//  itaka
//
//  Created by Robert Soszynski on 1/12/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Device.h"

@implementation Device
@synthesize identifier, name, model, systemName, systemVersion, batteryLevel, gps, delegate;

-(id)init
{
    if (self = [super init])
    {
        gps = [[GPS alloc]init];
        
        UIDevice *device = [UIDevice currentDevice];
        [device setBatteryMonitoringEnabled:YES];
        
        [self setIdentifier: device.uniqueIdentifier];
        [self setName: device.name];
        [self setModel: device.model];
        [self setSystemName: device.systemName];
        [self setSystemVersion: device.systemVersion];
        
        [gps setDelegate: self];
        
        [self update];
    }
    return self;
}

- (void) updateOnDemand {
    [gps startOnDemand];
}

- (void) update {
    [gps start];
}

- (void) updateBattery {
    UIDevice *device = [UIDevice currentDevice];
    [self setBatteryLevel: [NSNumber numberWithFloat:device.batteryLevel]];
}

- (void) GPSUpdated {
    /*if ([gps onDemand]) {
        [gps stopOnDemand];
    }*/
    [self updateBattery];
    
    [[self delegate] deviceUpdated];
}

@end